<?php

declare(strict_types=1);
/**
 * This file is part of MoChat.
 * @link     https://mo.chat
 * @document https://mochat.wiki
 * @contact  group@mo.chat
 * @license  https://github.com/mochat-cloud/mochat/blob/master/LICENSE
 */

namespace MoChat\App\Client\Logic\Detail;

use Hyperf\DbConnection\Db;

/**
 * 订单.
 *
 */
class OrderLogic
{

    /**
     * @throws \EasyWeChat\Kernel\Exceptions\InvalidConfigException
     * @throws \GuzzleHttp\Exception\GuzzleException
     */
    public function handle(array $params): array
    {
        //查询用户内码
        $res = Db::connection('b2b')->table('user_order')
            ->join('order_status', 'user_order.id', '=', 'order_status.id')
            ->join('user', 'user.id', '=', 'user_order.user_id')
            ->where('user_order.user_id', $params['clientId'])
            ->orderBy('user_order.create_time', 'desc')
            ->paginate((int)$params['perPage'], ['user_order.order_number as orderNumber', 'user.business_name as businessName', 'user.username', 'user.type', 'user_order.total_amount as totalAmount', 'user_order.paid_amount as paidAmount', 'user_order.create_time as createTime', 'user_order.payment_method as paymentMethod', 'order_status.status_ as status'])
            ->toArray();
        $data =  my_page($res);
        return $data;
    }
}
